package com.evil.common.es.dto;

import com.evil.common.es.enums.DimensionEnum;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.LinkedHashMap;

/**
 * 聚合树
 *
 * @author liyang
 * @date 2024-08-08 15:05
 */
@Data
@AllArgsConstructor
public class AggTreeParam<T> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 行名称
     */
    private LinkedHashMap<String, ? extends T> rowMap;
    /**
     * 列名称
     */
    private LinkedHashMap<String, ? extends T> columnMap;
    /**
     * 指标名称
     */
    private LinkedHashMap<String, ? extends T> targetMap;

    public AggTreeParam() {
        this.rowMap = new LinkedHashMap<>();
        this.columnMap = new LinkedHashMap<>();
        this.targetMap = new LinkedHashMap<>();
    }

    public DimensionEnum calDimension(String name) {
        if (rowMap.containsKey(name)) {
            return DimensionEnum.ROW;
        }
        if (columnMap.containsKey(name)) {
            return DimensionEnum.COLUMN;
        }
        return DimensionEnum.TARGET;
    }

    public boolean containsRow(String name) {
        return rowMap.containsKey(name);
    }

    public T getRow(String name) {
        return rowMap.get(name);
    }

    public boolean containsColum(String name) {
        return columnMap.containsKey(name);
    }

    public T getColum(String name) {
        return columnMap.get(name);
    }

    public boolean containsTarget(String name) {
        return targetMap.containsKey(name);
    }

    public T getTarget(String name) {
        return targetMap.get(name);
    }
}
